package com.base;

import android.app.Application;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;

import com.training.net.DataCenter;

public class MainApplication extends Application {
    private static MainApplication app;
    public String deviceId;
    private Handler mainHandler;
    
    public static MainApplication instance() {
        return app;
    }
    
    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        deviceId= Settings.Secure.getString(
                getContentResolver(),
                Settings.Secure.ANDROID_ID
        );
        mainHandler = new Handler(Looper.getMainLooper());
        DataCenter.instance().onCreate(this);
    }
    
    public Handler getMainHandler() {
        // 确保即使在app实例未通过onCreate初始化的情况下也能获得mainHandler
        if (mainHandler == null && app != null) {
            mainHandler = new Handler(Looper.getMainLooper());
        }
        return mainHandler;
    }
}